﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using BookStore.Solution.BLL;
using BookStore.Solution.Utilities;

namespace BookStore.Solution.Presentation
{
    public enum SearchIEType
    {
        ID,
        Reason
    }

    public partial class frmSearchIE : DevComponents.DotNetBar.OfficeForm
    {
        public DataTable ResultTable { get; set; }
        private IEManager manager = new IEManager();
        private SearchIEType Type;
        
        public frmSearchIE(SearchIEType type)
        {
            InitializeComponent();
            this.Type = type;
            switch (type)
            {
                case SearchIEType.ID:
                    Text = "Tìm kiếm theo mã chi tiêu";
                    break;
                case SearchIEType.Reason:
                    Text = "Tìm kiếm theo lý do";
                    break;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            ResultTable = null;
            Close();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            txtKeyword.Border.BackColor = StyleManager.ColorTint;
            if (txtKeyword.Text != "")
            {
                switch (Type)
                {
                    case SearchIEType.ID:
                        ResultTable = manager.SearchByID(DataUtil.ToInt(txtKeyword.Text));
                        break;
                    case SearchIEType.Reason:
                        ResultTable = manager.SearchByReason(txtKeyword.Text);
                        break;
                }
                if (ResultTable.Rows.Count == 0)
                {
                    MessageBox.Show("Không tìm thấy chi tiêu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    ResultTable = null;
                    txtKeyword.Border.BackColor = Color.Red;
                }
                else
                {
                    Close();
                }

            }
            else
            {
                MessageBox.Show("Từ khóa rỗng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                ResultTable = null;
                txtKeyword.Border.BackColor = Color.Red;
            }
        }
    }
}